package com.situ.mvc.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class MyInterceptor1 implements HandlerInterceptor{
	// 第一次访问时候会调用构造方法创建对象，后面再访问时候只是访问里面方法
	public MyInterceptor1() {
		System.out.println("MyInterceptor1.MyInterceptor1()");
	}

	// 
	/**
	 * previous
	  *  执行Controller方法之前执行该方法
	 * 返回true代表继续往后执行，返回false代表终止执行，不再往后执行
	 * 所以用户是否登录就可以写到之类，已经登录返回true，没有返回返回false
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
		System.out.println("MyInterceptor1.preHandle()");
		return true;
	}
	
	/**
	 * 执行Controller方法之后会执行该方法
	 * 但是是在返回ModelAndView之前
	 */
	@Override
	public void postHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, ModelAndView arg3)
			throws Exception {
		System.out.println("MyInterceptor1.postHandle()");
	}
	
	/**
	 * 执行Controller方法之后会执行该方法
	 * 并且ModelAndView视图已经返回执行
	 */
	@Override
	public void afterCompletion(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2, Exception arg3)
			throws Exception {
		System.out.println("MyInterceptor1.afterCompletion()");
	}

	

	

}
